package locations.actions;

import java.util.ArrayList;
import java.util.Collection;

import locations.dao.implement.PracticaDAOHibernateJPA;
import locations.model.Practica;
import locations.model.TipoPractica;

import com.opensymphony.xwork2.ActionSupport;
import locations.model.TipoProblematica;

public class EditPracticaAction extends ActionSupport{

    private static final long serialVersionUID = 1L;
    private Long id;
    private Practica practica;
    private Collection<Long> codigosPracticas = new ArrayList<Long>();
    private Collection<Long> codigosTipoProblematicas = new ArrayList<Long>();


    @Override
    public String execute() throws Exception
    {
        PracticaDAOHibernateJPA dao = new PracticaDAOHibernateJPA();
        this.setPractica(dao.retrieveById(this.getId()));

        for (TipoPractica each : this.getPractica().getTipoPracticas()) {
                this.getCodigosPracticas().add(each.getId());
        }

        for (TipoProblematica each : this.getPractica().getTipoProblematicas())
        {
            this.getCodigosTipoProblematicas().add(each.getId());
        }
        return SUCCESS;
    }
    public Long getId() {
            return id;
    }
    public void setId(Long id) {
            this.id = id;
    }
    public Practica getPractica() {
            return practica;
    }
    public void setPractica(Practica practica) {
            this.practica = practica;
    }
    public static long getSerialversionuid() {
            return serialVersionUID;
    }
    public Collection<Long> getCodigosPracticas() {
            return codigosPracticas;
    }
    public void setCodigosPracticas(Collection<Long> codigosPracticas) {
            this.codigosPracticas = codigosPracticas;
    }

    public Collection<Long> getCodigosTipoProblematicas()
    {
        return codigosTipoProblematicas;
    }

    public void setCodigosTipoProblematicas(Collection<Long> codigosTipoProblematicas)
    {
        this.codigosTipoProblematicas = codigosTipoProblematicas;
    }


}
